<html> <head>
<title>PYML Documentation</title>
</head>
<body>
<center><h2>PYML Introduction</h2></center>

PYML is a python interface to Mathematica which uses MathLink.  It
allows the Python programmer to evaluate Mathematica expressions.
Python objects which represent the expressions are passed to PYML,
which processes them into MathLink calls.  PYML calls MathLink to
evaluate the expression and then returns the result.  Currently, PYML
supports Mathematica 2.2 and 3.0.  The program is has reached a fairly
stable state.

The original interface was written by (<a
href="mailto:dek@cgl.ucsf.edu">David Konerding</a>) with assistance
and ideas from Konrad Hinsen (<a
href="mailto:hinsen@dirac.cnrs-orleans.fr">.  Contact the primary
author with bugfixes and ideas for improvements.<br>

The program is
available from <a
href="http://picasso.ucsf.edu/~dek/pyml/pyml-1.0pre.tgz">PYML
page</a>

<center><h2>PYML Installation</h2></center>

PYML is composed of a python module with some additional C code (the
interface to MathLink).  It is necessary to compile the C code into a
dynamically linked libary which is loaded by the PYML Python code.
PYML can be used on Win95/98/NT with Visual C++, and UNIX (Compaq
Alpha, HP-RISC, SGI, Solaris, AIX, Linux).<br>

You must first install <a href="www.mathematica.com">Mathematica</a>,
and the <a href="www.wolfram.com/solutions/mathlink/devkits.html">MathLink
software development kit</a>.<br>

To build the MathLink interface with Visual C++, you must first
install the <a href="http://www.python.org/Download">Python Windows
distribution</a>.  Then start Visual C++, load the workspace file and
select Build->Compile.  If Visual C++ is unable to find the MathLink
SDK, you must change the include file and library file directories for
the compiler in Options->Compilation Options.  Add the parent of
the pyml directory to your PYTHONPATH.<br>

To build the MathLink interface on UNIX, you must first install the <a
href="http://www.python.org/Download">Python Unix distribution</a>.
Then, enter the PYML directory and type "make -f Makefile.pre.in boot"
then "make".  If the compiler is unable to find the MathLink SDK, you
must edit the Makefile and change the include and library file
directories.  Once the DLL is compiled, add the parent directory of
pyml to your PYTHONPATH<br>

<center><h2>PYML Usage</h2></center>

All Mathematica expressions are composed of only functions, symbols,
strings, integers and reals.  Any Mathematica expression can be
represented in its full form by a Python object.  Examples of PYML
usage are found in the file <a href="pyml.py">pyml.py</a> file.  Here
is a basic tutorial.<br>

<center><h2>Entering functions</h2></center>

<center><h3>Full Form</h3></center>

The basic form of all functions in Mathematica is is the following pattern:<br>

<tt>In[1] := head[arguments]</tt><br>

where <emph>head</emph> is the name of the function and <emph>arguments</emph>
is a comma-delimited list of arguments.

The basic form of all functions in PYML is a valid Python object with
the following pattern::<br>

<tt>>>> head([list of arguments])</tt><br>

The full form of the function 1+x in Mathematica looks like:<br>
<tt>>>> Plus[1,x]</tt><br>

The full form of the function 1+x, written as a PYML object :<br>
<tt>>>> function =
MathematicaFunction("Plus",MathematicaInteger(1),[MathematicaSymbol("x")])</tt><br>


The PYML string representation of the function is the Mathematica full
form.  It can be cut and pasted into Mathematica.<br>

<tt>>>> print function<br>
<b>Plus[1,x]</b></tt><br>

To evaluate the function, you need to wrap it in an expression then
send it to Mathematica for evaluation:

<tt>>>> expression = MathematicaExpression(function)<br>
>>> e = m.evaluate(expression)<br>
>>> result= m.process()</tt><br>

The result is a PYML object representing a Mathematica Expression,
suitable for further input to PYML or to be cut and pasted into
Mathematica.<br>

<center><h3>Python Compact Form</h3></center>

As you can see, the full form is rather tedious.  You can usually
enter expressions using simpler code.

To simplify entering common expressions, you can use the normal
mathematical operators on the Mathematica
objects generate Full Form expressions (PYML expands these operators
into their Mathematica Full Form expressions for you):<br>

<tt>>>> Plus = MathematicaFunction("Plus")</tt><br>
<tt>>>> function = Plus(1+"x")</tt><br>
<tt>>>> print function<br>
<b>Plus[1,x]</b></tt><br>

or<br>

<tt>>>> x=MathematicaSymbol("x")</tt><br>
<tt>>>> function = 1+x</tt><br>
<tt>>>> print function<br>
<b>Plus[1,x]</b></tt><br>


In PYML expressions, quoted strings are interpreted as Mathematica
symbols.  Integers and reals are intepreted as Mathematica integers
and reals.  Strings must be explicitly created:

<tt>>>> string = MathematicaString("hello world")</tt><br>

<center><h3>More Complicated Functions</h3></center>

More complicated functions, such as integrals, are entered easily.<br>

The integral of x^2 with x varying from 0 to 2:<br>
<tt>function = Integrate(Power("x",2), List("x",0,2))</tt><br>

<center><h3>Plotting</h3></center>

You can plot (to a postscript file) functions just as you would in the
front end.  The output is saved to test.eps file.<br>

<tt>function = Plot((Times(Power(Sin("x"),"x"),"Pi")),List("x",0,"Pi"))</tt><br>


</body> <hr>
<a href="http://picasso.ucsf.edu/~dek/">David E. Konerding</a>
<!-- hhmts start -->
<!-- hhmts end -->
</html>
